home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / KADFILE.ZIP / PACKER.C < prev    next >
C/C++ Source or Header  |  1995-03-06  |  5KB  |  129 lines

  1. /****************************************************************************/
  2. /* PACKER file routines                                                        */
  3. /* Functions under DOS4Gw and PmodeW                                        */
  4. /*--------------------------------------------------------------------------*/
  5. /* Coded by Kodiak of The Apollo Project                                    */
  6. /* AKA Charles Jones                                                        */
  7. /*     1122 s 32nd St #2                                                    */
  8. /*     Omaha, NE 68105                                                      */
  9. /*     (402)-346-8974                                                       */
  10. /*                                                                          */
  11. /* Email: CAD@UnOmaha.edu                                                   */
  12. /* IRC  : #Coders                                                           */
  13. /*                                                                          */
  14. /*                                                                          */
  15. /* Copyright 1995 All Rights Reservered                                     */
  16. /* Released to public domain, but hey if you use it greet me.               */
  17. /****************************************************************************/
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include "dir.stc"
  21. #include "encrypt.h"
  22. #define buffersize 32000                    /* buffersize for copyfile */
  23. #define MAXDIRS 25
  24.    
  25.    FILE *file2, *file1;                       /* binary files */
  26.    FILE *Projectfile;                         /* text files */
  27.    dir_struc directory[MAXDIRS];              /* internal directory */
  28.    char *buffer[buffersize];                  /* copy buffer */
  29.  
  30. /****************************************************************************/
  31. /* Function : copyfile                                                      */
  32. /* IN : directory's entry number                                            */
  33. /* RETURNS:                                                                 */
  34. /*          nothing                                                         */
  35. /****************************************************************************/
  36. /* Note :                                                                   */
  37. /*      What do you think?                                                  */
  38. /****************************************************************************/
  39. void copyfile(int dirnum)
  40. {
  41.     int x;
  42.     int y;
  43.  
  44.     file2 = fopen(directory[dirnum].name,"r+b");
  45.  
  46.     y = 0;
  47.     x = buffersize;
  48.     while (x == buffersize)
  49.     {
  50.     x = fread(&buffer, 1, buffersize, file2);
  51.     y += x;
  52.     printf("%d \n",x);
  53.     fwrite(&buffer, 1, x, file1);
  54.     }
  55.     directory[dirnum].filesize = y;
  56.     fclose(file2);
  57. }
  58.  
  59. /****************************************************************************/
  60. /* Function : copyfile                                                      */
  61. /* IN : number of directory entries, and password                           */
  62. /* RETURNS:                                                                 */
  63. /*          nothing                                                         */
  64. /****************************************************************************/
  65. /* Note :                                                                   */
  66. /*      This function encrypts our directory entries and save to disk.      */
  67. /****************************************************************************/
  68. void write_directory(int numdirs, char *password)
  69.     encryptdir((char *) directory,numdirs,password);
  70.     fwrite(&directory, sizeof(dir_struc), numdirs, file1);
  71.     fwrite(&numdirs,sizeof(int),1,file1);
  72. }
  73.  
  74.  
  75. void main(int argc, char *argv[])
  76. {
  77.     int x;
  78.  
  79.     char buffer[35];
  80.  
  81.     if (argc != 4) {
  82.     printf("'PACKER PROJECTFILE OUTPUTFILE PASSWORD' Builds the KADfile\n"
  83.            " Note : \n"
  84.            "        If outfile is an EXE then KADfile is appended.\n"
  85.            "        Otherwise, outfile is created.\n");
  86.            return;
  87.     }
  88.      if (strstr(argv[2],".exe") != NULL) {
  89.      file1 = fopen(argv[2],"r+w+b");
  90.      fseek(file1, 0, 2);
  91.      }
  92.      else
  93.      file1 = fopen(argv[2],"w+b");
  94.  
  95.  
  96.      Projectfile = fopen(argv[1],"r");
  97.  
  98.      fgets(buffer,35,Projectfile);
  99.      buffer[35] = 0;
  100.      if (strstr(buffer,"Project File for KAD system. V1.0") == NULL) {
  101.      printf("Invalid Project File!\n");
  102.      fclose(Projectfile);
  103.      fclose(file1);
  104.      return;
  105.      }
  106.  
  107.  
  108.      x = -1;
  109.  
  110.      while (fgets(directory[++x].name, 13, Projectfile) != NULL)
  111.      {
  112.      if (x > MAXDIRS) {
  113.          printf("Out of directory space! Alter MAXDIRS and recompile!");
  114.          exit ( EXIT_SUCCESS );
  115.      }            
  116.      directory[x].name[strlen(directory[x].name)-1] = 0;
  117.      directory[x].filepos = ftell(file1);
  118.      printf("File #%d Name:%s Size:",x,directory[x].name);
  119.      copyfile(x);
  120.  
  121.      }
  122.  
  123.      write_directory(++x, argv[3]);
  124.  
  125.      fclose(Projectfile);
  126.      fclose(file1);
  127. }
  128.